<%@ page language="java" contentType="text/html; charset=utf-8"   pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<script language="javascript" src="${basePath}commonJs/tags/My97DatePicker/WdatePicker.js"></script>  
<title>嘉童游乐中心-付款申请</title>
<script type="text/javascript">
$(document).ready(function(){
	
	 initTab("form1", "table1", "foot1", initData);
	  
	 $("input[name='piaohao']").bind("click",function(){ 
		 var val=$('input:radio[name="piaohao"]:checked').val();
		 var inputNumId ="#"+val;
		 var inputNumValue =$("#oldNumHidden").val();
		 radioCheck(val,inputNumValue);
	 }); 
	 
	 $("#exportBtn").click(function() {
			$.messager.confirm('提示', '确定要导出付款明细吗？', function(r) {
				if (r) {
					$("#exportForm").submit();
				}
			});
		});
});

function radioCheck(val,inputValue){
	 if(val=="checkNo"){
		 $('#checkNo').removeAttr("disabled");
		 $('#cableNo').attr('disabled',"true");
		 $('#creditNo').attr('disabled',"true");
		 $('#checkNo').val(inputValue);
		 $("#cableNo").val(''); $("#creditNo").val('');
	 }
	 if(val=="cableNo"){
		 $('#cableNo').removeAttr("disabled");
		 $('#checkNo').attr('disabled',"true");
		 $('#creditNo').attr('disabled',"true");
		 $('#cableNo').val(inputValue);
		 $("#checkNo").val(''); $("#creditNo").val('');
	 }
	 if(val=="creditNo"){
		 $('#creditNo').removeAttr("disabled");
		 $('#checkNo').attr('disabled',"true");
		 $('#cableNo').attr('disabled',"true");
		 $('#creditNo').val(inputValue);
		 $("#checkNo").val(''); $("#cableNo").val('');
	 }
}
function initTab(formId, tableId, footId, initData) {
	
	var form = $("#" + formId);
	var pagebean = new PageBean(form);
	pagebean.setCallback(initData);
	pagebean.setFootId(footId);
	pagebean.setTableId(tableId);
	setPagebeanObj(pagebean);
	pagebean.doPage();
}

function getEditlUrl(pkPayformId,type){
	window.location.href='${basePath}scmInvocing/scmPayForm/invoOrderPayNew.shtml?type='+type+'&pkPayFormId='+pkPayformId;
}

function initData(data) { //初始化付款申请单 列表
	
	if(data!=null){
		$.each(data,function(ind,obj){
			var htm="<tr>";
			var indextd =ind+1;
			var userName = obj.userName;
			if(userName==null){
				userName ="";
			}
			var inputupdate ="getEditlUrl('"+obj.pkPayformId+"','edit')";
			var inputChuLidate ="getEditlUrl('"+obj.pkPayformId+"','chuli')";
			var inputChuTuiLidate ="getEditlUrl('"+obj.pkPayformId+"','chuli-tui')";
			/**处理*/
			 var option_handle = '<td><input type="button" class="btn_l" value="处理" onClick="'+inputChuLidate+'"></td>';
			 
			/**退回处理重新提交*/
			var option_handle_re='<td><input type="button" class="btn_l" value="重新提交" onClick="'+inputChuTuiLidate+'"></td>';
			var dateApply =getSmpFormatDate(new Date(obj.applyTime), true);
			var statusValue =obj.status;
			htm+="<td>"+indextd+"</td>";
			htm+='<td class="lv"><a href="${basePath}scmInvocing/scmPayForm/invoOrderPayNew.shtml?type=detail&pkPayFormId='+obj.pkPayformId+'">'+obj.pkPayformId+'</a></td>';
			htm+="<td>"+obj.supName+"</td>";
			htm+="<td>"+dateApply+"</td>";
			htm+="<td>"+userName+"</td>";
			var checkNo =obj.checkNo;var cableNo =obj.cableNo;var creditNo =obj.creditNo;
		    var numpiaoId="";
		    var numPiaoValue ="";
		    if(""!=cableNo){
		    	numPiaoValue =cableNo;
		    	numpiaoId ="cableNo";
		    }else if(""!=creditNo){
		    	numPiaoValue =creditNo;
		    	numpiaoId ="creditNo";
		    }else if(""!=checkNo){
		    	numPiaoValue =checkNo;
		    	numpiaoId="checkNo";
		    }
		     
			var inputPay ="openPiaoDiv('"+obj.pkPayformId+"','"+numPiaoValue+"','"+numpiaoId+"')";
			
			htm+="<td>"+obj.workflowVo.statusDesc+"</td> ";
			htm+='<td>'+(obj.workflowVo.result == null ? "":obj.workflowVo.result)+'</td>';
			if(statusValue=="1"){//草稿
				var  delpurOrder="del_purOrder('"+obj.pkPayformId+"')";
			htm+=' <td><input type="button" class="btn_l" value="编辑" onClick="'+inputupdate+'"><input type="button" onClick="'+delpurOrder+'" class="btn_l ml10" value="删除"></td>';
			}else if(statusValue=="2"){//2 审批中
			
				 if(obj.workflowVo.isCurrtOpt == '1')
				 {
				 	if(obj.workflowVo.isStartUser == '1')
				 		{
				 		 htm += option_handle_re;
				 		}
				 	else
				 		{
				 		htm += option_handle;
				 		}
				 }
			 else
				{
					htm += '<td></td>';
				}
			
			}else{//通过
				htm+='<td><input type="button" class="btn_l" onClick="'+inputPay+'" value="支付信息录入"  /></td>';
			}
			htm+="</tr>";
			 $("#table1").find("tr:eq("+ind+")").after(htm);
		});
	}
}


function del_purOrder(id){
	 $.messager.confirm('提示', '确认要删除吗?', function(r) {
		if(r){
			$.ajax({ 
				url: "${basePath }scmInvocing/scmPayForm/delPayFormById.shtml",
				data:"pkPayFormId="+id,
				type:'POST',
				success: function(data){
					 initTab("form1", "table1", "foot1", initData);
					alertInfo($common_delete_success);
		      	}
			});
		}
	 });
}

function searchOrderPay(){
	var pkPayformIdSearch =$("#pkPayformIdSearch").val();
	if(pkPayformIdSearch!=""){
		$("#pkPayformId").val(pkPayformIdSearch);
	}else{
		$("#pkPayformId").val("");
	}
	var startTimeShow =$("#startTimeShow").val();
	var endTimeShow =$("#endTimeShow").val();
	
	if(startTimeShow !=""){
		$("#startApplyTime").val(startTimeShow);
	}else{
		$("#startApplyTime").val("");
	}
	
	if(endTimeShow !=""){
		$("#endApplyTime").val(endTimeShow);
	}else{
		$("#endApplyTime").val("");
	}
	
	var supplyIdSearch = $("#supplyIdSearch").val();
	$("#supName").val(supplyIdSearch);
	select1("form1",initData);
}

function afterDate(){
	var startDateShow =$("#startTimeShow").val();
	var afterDate="";
	if(startDateShow!=""){
		afterDate = startDateShow;
	}
	  
	 return afterDate;
}

function openPiaoDiv(obj,numPiaoValue,numpiaoId){
	$("#payformIdHidden").val(obj);
	$('#addfukuan').window('open');
	if(""!=numPiaoValue){
		$("#oldNumHidden").val(numPiaoValue);
		radioCheck(numpiaoId,numPiaoValue);
		var qnumpiaoId ="#"+numpiaoId;
		$(qnumpiaoId).val(numPiaoValue);
		//var qnuraidoId ="#"+numpiaoId+"r1";
		//$(qnuraidoId).attr("checked",true);
		$("input:radio[value="+numpiaoId+"]").attr("checked",true);
	}else{
		
		radioCheck("checkNo",'');
		$("input[@type=radio][id=checkNor1]").attr("checked",true);
	}
}
function savePiaoHao(){
	var val=$('input:radio[name="piaohao"]:checked').val();
	if(val==null){
		alertWarning("请选择票号!");
		return false;
	}
	else{
		var inputNumId ="#"+val;
		var inputNumValue =$(inputNumId).val();
		if(null== inputNumValue || "" ==inputNumValue){
			alertWarning("请输入票号!");
		}else{
			$("#oldNumHidden").val(inputNumValue);
			 var checkNo ="";//支票号
			 var cableNo ="";//电汇票号
			 var creditNo ="";//贷记票号
			 if(val=="checkNo"){
				 checkNo =$("#checkNo").val();//支票号
				 $('#checkNo').removeAttr("disabled");
				 $('#cableNo').attr('disabled',"true");
				 $('#creditNo').attr('disabled',"true");
			 }
			 if(val=="cableNo"){
				 cableNo =$("#cableNo").val();//电汇票号
				 $('#cableNo').removeAttr("disabled");
				 $('#checkNo').attr('disabled',"true");
				 $('#creditNo').attr('disabled',"true");
			 }
			 if(val=="creditNo"){
				 creditNo =$("#creditNo").val();//贷记票号
				 $('#creditNo').removeAttr("disabled");
				 $('#checkNo').attr('disabled',"true");
				 $('#cableNo').attr('disabled',"true");
			 }
			  
			 var payformIdHidden =$("#payformIdHidden").val();
					$.ajax({ 
						url: "${basePath }scmInvocing/scmPayForm/savePiaoHao.shtml",
						data:"fkPayformId="+payformIdHidden+"&checkNo="+checkNo+"&creditNo="+creditNo+"&cableNo="+cableNo,
						type:'POST',
						success: function(data){
							alertInfo("保存成功。");
							window.location.href="${basePath }scmInvocing/scmPayForm/findInvoOrderPay.shtml";
				      	}
					});
					 
		}
		
	}
	//$('#addfukuan').window('close');
}

//设置pageNo为1
function select1(formId,initData){
	$("#"+formId+ " input:hidden[name='pageNo']").val(1);
	initTab(formId, "table1", "foot1", initData);
}

//跟换门店
function branSelectFun() {
	var branVal  = $("#branIdSelect").val();
	if(branVal == -1)
		{
			$("#fkBranId").val("");
		}
	else
		{
			$("#fkBranId").val(branVal);
		}
}
</script>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
                 <shiro:hasPermission name="scmInvocing/productInfo/forwardToProductInfo.shtml">
    				  <li><a href="${basePath}scmInvocing/productInfo/forwardToProductInfo.shtml"><i class="nav_icon_b"></i><br>商品信息</a></li>
    		</shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/countUnit/forwardToUnitInfo.shtml">
    		 		<li><a href="${basePath}scmInvocing/countUnit/forwardToUnitInfo.shtml"><i class="nav_icon_b"></i><br>单位设置</a></li>
    		 </shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/supplier/forwardToSupply.shtml">
    		 		   <li><a href="${basePath}scmInvocing/supplier/forwardToSupply.shtml"><i class="nav_icon_a"></i><br>供应商信息</a></li>
    		 </shiro:hasPermission>
    		  <shiro:hasPermission name="scmInvocing/priceManager/forwardToList.shtml">
    		 		  <li><a href="${basePath}scmInvocing/priceManager/forwardToList.shtml"><i class="nav_icon_f"></i><br>价格管理</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPurOrder/findInvoPurOrder.shtml">
            	  <li><a href="${basePath}scmInvocing/scmPurOrder/findInvoPurOrder.shtml"><i class="nav_icon_b"></i><br>采购订单</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPayForm/findInvoOrderPay.shtml">
           		   <li  class="content_hover"><a href="${basePath}scmInvocing/scmPayForm/findInvoOrderPay.shtml"><i class="nav_icon_b"></i><br>付款申请</a></li>
    		 </shiro:hasPermission></ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
		<div class="file_single_dl f14 fixed">
		 <form action="${basePath}scmInvocing/scmPayForm/exportPayDetailed.shtml" method="post" id="exportForm">
			    	<dl  class="fixed" style="overflow:hidden">
			    	     <dd><label>供应商：</label> 
			    	     	<input id="supplyIdSearch" name="supName" type="text" class="iput_t w200">
			    	     </dd>
		                         <dd><label>付款申请编号：</label><input id="pkPayformIdSearch" name="code" type="text" class="iput_t w200"></dd>
		                    <dd><label>所属门店：</label>
	                		<!----select--->
	                  	 	<div class="uboxstyle">
	                        	<select name="branId" id="branIdSelect" onchange="branSelectFun();">
	                        	<c:if test="${isZongBU == 1}">
	                        	<option value="-1" selected="selected">全部</option>
	                        	</c:if>
                        		<c:forEach items="${branList}" var="bran">
                        			<option value="${bran.pkBranId}">${bran.branName}</option>
                        		</c:forEach>
	                        	</select>
	                   		 </div>
	                   		 <!----select--->
                 		</dd> 
		                      <dd style="width:700px;"><label>申请时间：</label>
		                  <input id="startTimeShow" type="text" name="startTime" class="Wdate iput_t w150" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true})">
						<span>至</span>
						<input type="text" id="endTimeShow" class="Wdate iput_t w150" name="endTime" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{afterDate()}',isShowWeek:true,isShowClear:true,readOnly:true})">      
						     </dd>
		             <dd class="fr"><input type="button" onclick="searchOrderPay()" class="btn fr ml10" value="查询">
		             <shiro:hasPermission name="scmorderpay:add"> 
		             <input class="btn ml10 fr" type="button" value="创建付款申请" onClick="window.location.href='${basePath}scmInvocing/scmPayForm/invoOrderPayNew.shtml?type=add&pkPayFormId='">
		             </shiro:hasPermission>
		             <input class="btn ml10 fr" id="exportBtn" type="button" value="导出付款明细"  >
		            </dd>
		             </dl>   
		             </form>
        </div>
       
        <div class="mt10">
          	<ul class="fixed" id="tab_conbox_a">
                <li class="p10 h450" style="margin-left:10px">
                <form action="${basePath}scmInvocing/scmPayForm/findScmPayformEntityList.shtml" method="post" id="form1">
                  <input type="hidden" name="pageSize" value="10"> <input type="hidden" name="pageNo" value="1">
                  <input type="hidden" name="pkPayformId" id="pkPayformId">
                  <input type="hidden" name="fkBranId" id="fkBranId">
                   <input type="hidden" name="startApplyTime" id="startApplyTime"> 
                   <input type="hidden" name="endApplyTime" id="endApplyTime">
                   <input type="hidden" name="supName" id="supName">
                	<table class="table"  id="table1">
                    	<tr>
                        	<th>序号</th>
                            <th>付款申请编号</th>
                            <th>供应商名称</th>
                            <th>申请日期</th>
                            <th>申请人</th>
                            <th>审批状态</th> 
                            <th>审批结果</th> 
                            <th>操作</th>
                        </tr>
                    </table>
                      <!---翻页-->
                    <div class="page fr m10" id="foot1">
							</div>
                    <!----->
                    </form>
                  
                </li>
                </ul>
                </div>
        </div>
    </div>
</div>
<!---弹出层 成员信息编w辑--->
<div id="addfukuan" class="easyui-window" title="支付信息录入" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:400px; height:250px;position:relative;">
	<div class="editor_h1 fixed">
      <div class="editor fl">
            <ul>
                <li><label><input type="radio" id="checkNor1"   value="checkNo" name="piaohao" class="mr5">支票号&nbsp;&nbsp;&nbsp;：</label>
                <input id="checkNo"  type="text"   class="iput_t w160"></li>
                 <li><label><input type="radio" id="cableNor2"   value="cableNo" name="piaohao" class="mr5">电汇票号：</label>
                 			<input  id="cableNo"   type="text"  class="iput_t w160"><input  id="payformIdHidden"  type="hidden">
                 			<input  id="oldNumHidden"  type="hidden">
                 			</li>
                  <li><label><input type="radio"  id="creditNor3"    value="creditNo" name="piaohao" class="mr5">贷记票号：</label>
                  <input id="creditNo"   type="text"  class="iput_t w160"></li>
            </ul>
        </div>
    </div>
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onClick="savePiaoHao()" value="确定"></dd>
            <dd><input type="button" class="btn" onClick="$('#addfukuan').window('close')" value="取消"></dd>
        </dl>
    </div>
</div>
</body>
</html>














